#include <stdio.h>
#include <stdlib.h>
#include<iostream>
using namespace std;

typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;

List Read();
void Print( List L ); 

List Merge( List L1, List L2 );

int main()
{
    List L1, L2, L;
    L1 = Read();
    L2 = Read();
    L = Merge(L1, L2);
    Print(L);
    return 0;
}

List Read(){
    List head,p1,p;
    head=(PtrToNode)malloc(sizeof(struct Node));
    p1=head;
    while(1){
        p=(PtrToNode)malloc(sizeof(struct Node));
        scanf("%d",&p->Data);
        if(p->Data==-1){break;}
        p1->Next=p;
        p1=p1->Next;
    }
    p1->Next=NULL;
    return head;


}
void Print( List L ){
    List p;
    p=L->Next;
    if(L->Next==NULL){
        printf("NULL");
    }
    else{
        while(p->Next!=NULL) {
        printf("%d ", p->Data);
        p = p->Next;
      }
      printf("%d", p->Data);
    }

}
List Merge( List L1, List L2 ){
    if(!L1 &&!L2){return NULL;}
    List p1 = L1->Next,p2 = L2->Next,p;
    List L = (List)malloc(sizeof (List));
    L->Next = NULL;
    p = L;
    while(p1 && p2){
        if(p1->Data<p2->Data){
            p1 =p1->Next;
        }
        else if(p1->Data==p2->Data){
            p->Next = p1;
            p1 =p1->Next;
            p2=p2->Next;
            p = p->Next;
        }
        else{
            p2 =p2->Next;
        }
    }
    p->Next = NULL;
    L1->Next = NULL;
    L2->Next = NULL;
    return L;
}


